package com.hsoft.zhxy.app.xtgl_02_01.service.impl;


import com.hsoft.zhxy.app.xtgl_02_01.mapper.JcggDmxMapper;
import com.hsoft.zhxy.app.common.model.entity.JcggDmx;
import com.hsoft.zhxy.app.xtgl_02_01.service.JcggDmxService;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import org.apache.commons.lang3.StringUtils;
import com.hsoft.zhxy.common.base.BaseService;
import com.hsoft.zhxy.common.result.ResultBody;
import com.hsoft.zhxy.common.util.UUIDUtils;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;

 /**
 * All rights Reserved, Designed By 哈尔滨工业大学软件工程股份有限公司
 * 
 * @Title: 代码项 Service层接口实现类
 * @Package 
 * @Description: 
 * @author: system
 * @date: 2020-10-26
 */
@Log4j2
@Service
public class JcggDmxServiceImpl extends BaseService implements JcggDmxService {

    @Autowired
    private JcggDmxMapper jcggDmxMapper;


    /**
     * 查询单条数据
     * @param jcggDmx
     * @return
     */
    public JSONObject findOne(JcggDmx jcggDmx) {
        JcggDmx rs = jcggDmxMapper.selectOne(new QueryWrapper<JcggDmx>().setEntity(jcggDmx));
        return ResultBody.setData(rs);
    }


    /**
     * 查询列表数据
     * @param jcggDmx
     * @return
     */
    public JSONObject findList(JcggDmx jcggDmx) {
        List<JcggDmx> list = jcggDmxMapper.selectList(new QueryWrapper<JcggDmx>().setEntity(jcggDmx));
        return ResultBody.setData(list);
    }


    /**
     * 查询分页数据
     * @param jcggDmx
     * @param page
     * @param pageSize
     * @return
     */
    public JSONObject findListByPage(JcggDmx jcggDmx, long page, long pageSize) {

        Page<JcggDmx> pageObj = new Page<JcggDmx>(page, pageSize);
        QueryWrapper<JcggDmx> queryWrapper = new QueryWrapper<JcggDmx>();
        queryWrapper.eq("dmflbs",jcggDmx.getDmflbs())
                .like(StringUtils.isNotBlank(jcggDmx.getDmmc()),"dmmc",jcggDmx.getDmmc())
                .isNull(StringUtils.isBlank(jcggDmx.getSjdmid()),"sjdmid")
                .eq(StringUtils.isNotBlank(jcggDmx.getSjdmid()),"sjdmid",jcggDmx.getSjdmid())
                .eq(StringUtils.isNotBlank(jcggDmx.getDmid()),"dmid",jcggDmx.getDmid())
                .orderByAsc("pxh");
        IPage<JcggDmx> result = jcggDmxMapper.selectPage(pageObj, queryWrapper);
        return ResultBody.setData(result.getTotal(), result.getRecords());
    }


    /**
     * 新增
     * @param jcggDmx
     * @return
     */
    public JSONObject add(JcggDmx jcggDmx) {
        jcggDmx.setDmid(UUIDUtils.getUUID());
        jcggDmx.setSfky(1);
        jcggDmx.setCjsj(LocalDateTime.now());
        jcggDmx.setCjr(getYhid());
        jcggDmx.setBgsj(LocalDateTime.now());
        jcggDmx.setBgr(getYhid());
        return ResultBody.setData(jcggDmxMapper.insert(jcggDmx));
    }


    /**
     * 修改
     * @param jcggDmx
     * @return
     */
    public JSONObject update(JcggDmx jcggDmx) {
        jcggDmx.setBgsj(LocalDateTime.now());
        jcggDmx.setBgr(getYhid());
        return ResultBody.setData(jcggDmxMapper.updateById(jcggDmx));
    }


    /**
     * 删除
     * @param jcggDmx
     * @return
     */
    public JSONObject delete(JcggDmx jcggDmx) {
        return ResultBody.setData(jcggDmxMapper.delete(new QueryWrapper<JcggDmx>().setEntity(jcggDmx)));
    }


}
